// pages/subject-list/subject-list.js
import { baseUrl } from './../../util/util.js'
Page({
  data: {
    list: [],
    page: 0,
    isLoading: false,
    tag: ''
  },
  onLoad: function (options) {
    let { type } = options
    this.setData({
      tag: type
    })
    wx.setNavigationBarTitle({
      title: type
    })
    this.loadData(type)
  },
  loadData: function (type) {
    let { page, list } = this.data
    wx.showLoading({
      title: '正在拼命加载中...',
      mask: true
    })
    this.setData({
      isLoading: true
    })
    wx.request({
      url: `${baseUrl}h5-view/v/movie/list/?page_start=${this.data.page}&tag=${type}`,
      success: res => {
        page += 10
        list.push(...res.data.subjects)
        this.setData({
          list: list,
          page,
          isLoading: false
        })
        wx.hideLoading()
      }
    })
  },
  scrollToLower: function () {
    if (!this.data.isLoading) {
      this.loadData(this.data.tag)
    }
  },
  goToDetail: function (e) {
    wx.navigateTo({
      url: `/pages/detail/detail?id=${e.currentTarget.dataset.id}`,
    })
  }
})